# Author    : CoffeeChicken
# Date      : 2020-10-06 14:10
# Function  : 演示 匹配HTML标签

import re
import requests

headers = {
    'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
                  "Chrome/85.0.4183.121 Safari/537.36"
}

html_text = ""

for i in range(1, 5):
    with open("sexy/sexy" + str(i) + ".html", 'r') as fp:
        html_text += fp.read()

ex = '<a class="btn btn-primary btn-block text-white btn-md" target="_blank" href="(.*?)" download="">'

img_src_list = re.findall(ex, html_text, re.S)

for index in range(0, len(img_src_list)):
    res_url = img_src_list[index].replace("amp;", "")
    img_response = requests.get(res_url, headers=headers)
    with open("sexy_pics/" + str(index) + ".jpg", 'wb') as fp:
        fp.write(img_response.content)
    print(res_url)

print(len(img_src_list))
